package com.judian.smart.util;

import com.judian.smart.constant.Constants;
import com.judian.smart.net.IRetrofitApi;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * author: Peter
 * date: 2019/08/10 星期六 14:48
 * desc: 饿汉式单例模式
 */
public class RetrofitUtil {
    private static RetrofitUtil sRetrofitUtil = new RetrofitUtil();

    private RetrofitUtil() {
    }

    public static RetrofitUtil getInstance() {
        return sRetrofitUtil;
    }

    /**
     * 端口1168 一般图片 下载专案使用
     * 可监听进度
     *
     * @return 设置了拦截器的retrofit接口对象
     */
    public static IRetrofitApi retrofitCall() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.PICTUREHTTPS)
                .addConverterFactory(GsonConverterFactory.create())
                .client(okHttpClient)
                .build();
        return retrofit.create(IRetrofitApi.class);
    }

    /**
     * 端口 和利扬->99 声力->2222
     *
     * @return 没设置拦截器的retrofit接口对象
     */
    public static IRetrofitApi retrofitCallHTTP() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.HTTPS)
                .addConverterFactory(GsonConverterFactory.create())
                .client(new OkHttpClient())
                .build();
        return retrofit.create(IRetrofitApi.class);
    }

}
